package com.qiangqiang.resoldhouse.controller;

import com.qiangqiang.resoldhouse.dto.PageDTO;
import com.qiangqiang.resoldhouse.entity.Estate;
import com.qiangqiang.resoldhouse.entity.EstateSelect;
import com.qiangqiang.resoldhouse.service.EstateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author: zqh
 * @date: 2018/8/9 15:48
 * @description:
 */
@Controller
public class EstateController {

    @Autowired
    private EstateService estateService;

    @RequestMapping("/estate_list")
    public String getList(@RequestParam(name = "page", defaultValue = "1") Integer page,
                          Map<String, Object> map, EstateSelect select){
        if(select.getOrder() == null) select.setOrder("default");
        if(select.getEstateName() == null || select.getEstateName().trim().equals("")) select.setEstateName(null);
         map.put("pageDTO", estateService.findPage(page,select));
         map.put("select", select);
         return "estate_list";
    }

    @RequestMapping("/estate_detail")
    public String getDetails(@RequestParam(name = "estateId") Long estateId, Map<String, Object> map){
        map.put("estate", estateService.findEstateById(estateId));
        return "estate_detail";
    }

}
